//
//  NSUserDefaults+ZXExtension.m
//  ZXOCWeiBo
//
//  Created by mac on 15/12/2.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "NSUserDefaults+ZXExtension.h"

@implementation NSUserDefaults (ZXExtension)
/**
 *  保存当前版本号到偏好设置
 */
+(void)saveCurrentVersion
{
    NSString * currentVersion = [self VersionFromInfoPlist];
    //将版本号保证在用户偏好设置中
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:currentVersion forKey:KVersionInSandBox];
    //同步
    [defaults synchronize];
}

/**
 *  获取沙盒的版本号
 */
+(NSString *)VersionFromSandBox
{
    return [[NSUserDefaults standardUserDefaults]objectForKey:KVersionInSandBox];
}

/**
 *  获取InfoPlist的版本号
 */
+(NSString *)VersionFromInfoPlist
{
    NSDictionary * info = [NSBundle mainBundle].infoDictionary;
    //获得版本号
    NSString * verionKey = (__bridge NSString *) kCFBundleVersionKey;
    return info[verionKey];
}

@end
